<?php
/**
* 所有页面均使用utf-8编码
*/
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');  
// 响应类型  
header('Access-Control-Allow-Methods:POST');  
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  

#获取前台数据
if( isset( $_POST['phone'] ) ){
	$name  =  $_POST['name'];
	$phone =  $_POST['phone'];		
	// $class =  $_POST['class'];
	$msg   = $_POST['message'];
	$from  = $_POST['from'];

	sendmail( $name , $phone , $msg , $from );
}else{
	# 邮件发送失败
	// echo false;
}

#邮件处理函数
function sendmail( $nm , $ph , $msg, $from ){

	require_once( "mail/class.phpmailer.php" );
	require_once( "mail/class.smtp.php" );
	#设置时区
	date_default_timezone_set( "Asia/Shanghai" );

	$mail = new PHPMailer();

	#设置发送形势smtp
	$mail->IsSmtp();

	#设置编码
	$mail->CharSet = 'utf-8';

	#设置测试类型
	$mail->SMTPDebug = 1;

	#启用smtp的验证功能
	$mail->SMTPAuth = true;

	#发送方邮箱服务器
	$mail->Host = "smtp.163.com";

	#邮件发送端口
	$mail->Port = 25;

	#发送邮件的账号
	$mail->Username = "lgltlong@163.com";

	#发送邮件的密码
	$mail->Password = "Guoliang1989";

	#添加接收方账号
	$mail->AddAddress( "1271004590@qq.com" , "顺利办" );

	#邮件标题
	$mail->Subject = "客户咨询ing：" . $ph;

	#设置发件人信息
	$mail->From = "lgltlong@163.com";

	#发件人名字
	$mail->FromName = "霍克";

	#邮件内容
	$mail->Body = "姓名：$nm \n 电话 ：$ph \n 留言：$msg \n 来源：$from";

	#发送
	if( $mail->send() ){
		echo "send success";
	}else{
		# 邮件发送失败
	}

}
